package C30;

import java.util.Arrays;

/**
 * ClassName: Code05_DoubleNumber
 * Package: C30
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/12/17 15:37
 * @Version 1.0
 * @Since 1.0
 */
public class Code05_DoubleNumber {
    public static void main(String[] args) {
        int[] arr = {1,1,2,3,4,4};
        System.out.println(Arrays.toString(process(arr)));
    }

    /**
     *
     * @param arr
     * @return
     */
    public static int[] process(int[] arr) {
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            res ^= arr[i];
        }
        // 找出res 最右的1, 并单独提取出来
        int rightEor = res & (~res + 1);
        int res2 = 0;
        for (int i = 0; i < arr.length; i++) {
            if((arr[i] & rightEor) == 0) {
                res2 ^= arr[i];
            }
        }

        return new int[]{res ^ res2, res2};
    }
}
